#include<iostream>
#include<unordered_map>
#include<string>
using namespace std;

class Solution {
public:
    string minWindow(string s, string t)
    {
        unordered_map<char, int> hash1;
        for (auto it : t)
        {
            hash1[it]++;
        }
        int n = s.size();
        int des = hash1.size();
        int res = -1;
        int len = INT_MAX;
        unordered_map<char, int> hash2;
        for (int left = 0, right = 0, count = 0; right < n; right++)
        {
            char in = s[right];
            hash2[in]++;
            if (hash2[in] == hash1[in])count++;

            while (count == des)
            {
                if (right - left + 1 <= len)
                {
                    res = left;
                    len = right - left + 1;
                }

                char out = s[left];
                if (hash2[out] == hash1[out])count--;
                hash2[out]--;
                left++;
            }
        }

        if (res == -1)
        {
            return "";
        }
        else
        {
            return s.substr(res, len);
        }
    }
};

int main()
{
    Solution s1;
    string s, t;
    s = "ADOBECODEBANC";
    t = "ABC";

    s1.minWindow(s, t);
	return 0;
}